package ferp.core.calc.scorer;

import ferp.core.calc.Calculator;
import ferp.core.game.Game;
import ferp.core.game.Settings;
import ferp.core.player.Player;

/**
 * User: olegs
 * Date: 12/3/13 2:04 PM
 */
public class TrickingHalfWhist extends Scorer
{
  public static final TrickingHalfWhist instance = new TrickingHalfWhist();

  @Override
  protected void update(Game g, Settings settings, Calculator c)
  {
    int contract = g.contract();

    // write to declarer pool
    c.writeToPool(g, settings, g.declarer(), c.getPlayCostSuccess(contract));
    // write half whist to half whister
    c.writeToWhists(g, g.half(), g.declarer(), c.getWhistCostSuccess(contract) * Calculator.getExpectedStandingWhists(contract));
  }

  @Override
  protected void statistics(Game g)
  {
    for (Player p : g.players())
      if (p == g.declarer())
        g.statistics.updateTricking(p.id(), g.contract(), g.getDeclarerTricks());
      else
        g.statistics.passes[p.id()]++;
  }
}
